/*
 * 1.00 2012/10/15
 *
 * Copyright (c) 2012 Motch_bs
 * All rights reserved.
 *
 * このソフトウェアは，Motch_bsに所有される機密情報である。
 * これらの機密情報を漏洩してはならず，Motch_bs の意図する
 * 認可の元においてこれを使用すべし。
 */
package jp.co.ufp.voicetch.base.listener;

import jp.co.ufp.voicetch.base.dialog.PlayingDialog;
import jp.co.ufp.voicetch.base.dialog.RecordingDialog;
import jp.co.ufp.voicetch.base.logics.Logic020;
import jp.co.ufp.voicetch.base.logics.Logic040;
import jp.co.ufp.voicetch.base.logics.Logic050;
import jp.co.ufp.voicetch.base.util.AudioControler;
import jp.co.ufp.voicetch_free.R;
import android.app.Activity;
import android.media.MediaPlayer;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;

/**
 * @author Motch_bs
 * 
 */
public class MainOnClickListener implements OnClickListener {

    /** Main Activity */
    private Activity activity;

    /** 音楽再生 */
    private MediaPlayer mediaPlayer;

    /** 音源録音・再生 */
    private AudioControler audioControler;

    /** 録音時間 */
    private long recoringTime = 5000;

    /** 周波数 */
    private int rate = 8000;

    /**
     * @param activity
     * @param mediaPlayer
     */
    public MainOnClickListener(
	Activity pActivity, MediaPlayer pMediaPlayer, long pRecoringTime,
	int pRate) {
	super();
	this.activity = pActivity;
	this.mediaPlayer = pMediaPlayer;
	this.recoringTime = pRecoringTime;
	this.rate = pRate;
	audioControler = new AudioControler();
    }

    /** ボタンクリックイベント */
    public void onClick(
	View v) {
	int vid = v.getId();
	// View IDでイベントを判断
	switch (vid) {
	case R.id.btnHellow:
	    // 最大音量値を取得
	    mediaPlayer.setVolume(0.6f, 0.6f);
	    mediaPlayer.start();
	    break;
	case R.id.btnRecord:
	    RecordingDialogListener recordlistener = new
		    RecordingDialogListener(activity, audioControler, recoringTime);
	    RecordingDialog alertRecoring = new RecordingDialog(activity, recordlistener);
	    alertRecoring.showAlert(R.string.titleConfirm, R.string.msgRecordStart);
	    break;
	case R.id.btnPlayNormal:
	    Logic020 logic020 = new Logic020(activity, audioControler, rate);
	    Thread t020 = new Thread(logic020);
	    t020.start();
	    break;
	case R.id.btnPlayRobbot:
	    Logic020 logic021 = new Logic020(activity, audioControler, 4000);
	    Thread t021 = new Thread(logic021);
	    t021.start();
	    break;
	case R.id.btnPlayFftCpp:
	    PlayingDialogListener playinglistener = new
		    PlayingDialogListener(activity, audioControler, rate);
	    PlayingDialog alertPlaying = new PlayingDialog(activity, playinglistener);
	    alertPlaying.showAlert(R.string.titleConfirm, R.string.msgConvertStart);
	    break;
	case R.id.btnPlayFftJava:
	    Logic040 logic040 = new Logic040(activity, audioControler, rate);
	    Thread t040 = new Thread(logic040);
	    t040.start();
	    break;
	case R.id.btnPlayWavNormal:
	    Logic050 logic050 = new Logic050(activity, audioControler, rate);
	    Thread t050 = new Thread(logic050);
	    t050.start();
	    break;

	default:
	    Log.d("MainOnClickListener", "想定外のボタンが押下されました。");
	    break;
	}

    }
}
